package com.java.excend.exer_1;

/**
 * @author luzhikun
 * @date 2020/12/5- 17:44
 */
public class CheckAccount extends Account {
    private double overdraft;

    public CheckAccount() {

    }

    public CheckAccount(int id, double balance, double annuallnterestRate, double overdraft) {
        super(id, balance, annuallnterestRate);
        this.overdraft = overdraft;
    }

    public void setOverdraft(double overdraft) {
        this.overdraft = overdraft;
    }

    public double getOverdraft() {
        return overdraft;
    }

    //取钱 有透支金额
    public void withdraw(double amount) {
        if (getBalance() >= amount) {
            //方式一
            super.setBalance(getBalance() - amount);
            System.out.println("余额为：" + getBalance());
            //方式二
            //super.withdraw(amount);
        } else {
            if (amount >= (overdraft + getBalance())) {
                double a = amount - (overdraft + getBalance());
                overdraft -= a;
                System.out.println("您的透支金额不足" + "还差：" + a);
            } else {
                double b = amount - getBalance();
                setBalance(0);
                overdraft -= b;
                System.out.println("本次取钱金额为：" + amount + "透支金额为:" + b);
            }
        }
    }

}
